package pers.lonestar.framework.utils.support.read;

import java.io.File;
import java.io.InputStream;

import pers.lonestar.framework.utils.support.metadata.read.ReadWorkbook;

public class ExcelReaderBuilder {
    private final ReadWorkbook readWorkbook;

    public ExcelReaderBuilder() {
        this.readWorkbook = new ReadWorkbook();
    }

    public ExcelReaderBuilder file(File file) {
        readWorkbook.setFile(file);
        return this;
    }

    public ExcelReaderBuilder file(String fileName) {
        readWorkbook.setFile(new File(fileName));
        return this;
    }

    public ExcelReaderBuilder file(InputStream inputStream) {
        readWorkbook.setInputStream(inputStream);
        return this;
    }

    public ExcelReaderSheetBuilder sheet() {
        return sheet(null, null);
    }

    public ExcelReaderSheetBuilder sheet(Integer sheetIndex) {
        return sheet(sheetIndex, null);
    }

    public ExcelReaderSheetBuilder sheet(String sheetName) {
        return sheet(null, sheetName);
    }

    public ExcelReaderSheetBuilder sheet(Integer sheetIndex, String sheetName) {
        ExcelReaderSheetBuilder readerSheetBuilder = new ExcelReaderSheetBuilder(build());
        if (sheetIndex != null) {
            readerSheetBuilder.sheetIndex(sheetIndex);
        }
        if (sheetName != null) {
            readerSheetBuilder.sheetName(sheetName);
        }
        return readerSheetBuilder;
    }

    public ExcelReader build() {
        return new ExcelReader(readWorkbook);
    }
}
